package com.tool.server.impl;

import com.tool.server.Email;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author liuxuhuang
 * @Product IntelliJ IDEA
 * @Package com.tool.com.tool.server.impl
 * @Title sendImpl
 * @Description:
 * @email liuxuhuang3970@qq.com
 * @date 2021/10/25 16:31
 */
@Service
public class SendEmailImpl implements Email {

    @Resource
    private JavaMailSender mailSender;

    @Value("${spring.mail.username}")
    private String from;

    @Override
    public boolean snedEmail(String to, String subject, String content) {
        new Thread(() -> {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom(from);
            message.setTo(to);
            message.setSubject(subject);
            message.setText(content);
            mailSender.send(message);
        }).start();
        return true;
    }
}
